package edu.cmu.cs.stage3.alice.authoringtool.datatransfer;

import java.awt.datatransfer.DataFlavor;

/**
 * @author Jason Pratt
 */
public class ObjectArrayPropertyItemTransferable implements java.awt.datatransfer.Transferable {

 //LOB version using 'mimeType' to create 'java.awt.datatransfer.DataFlavor' produce error in Java 5, changed to 'Class'
 //LOB public final static java.awt.datatransfer.DataFlavor objectArrayPropertyItemFlavor = new java.awt.datatransfer.DataFlavor( java.awt.datatransfer.DataFlavor.javaJVMLocalObjectMimeType + "; class=edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyItem", "objectArrayPropertyItemFlavor" );
 //LOB
 public static java.awt.datatransfer.DataFlavor objectArrayPropertyItemFlavor = null;
 private final static String str1 = java.awt.datatransfer.DataFlavor.javaJVMLocalObjectMimeType;
 static { try {
   // String str2 = str1 + "; class=edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyItem";
   // java.awt.datatransfer.DataFlavor objectArrayPropertyItemFlavor =
   //   new java.awt.datatransfer.DataFlavor( str2, "objectArrayPropertyItemFlavor" ); // e.toString()
   String str2 = "edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyItem";
   java.awt.datatransfer.DataFlavor objectArrayPropertyItemFlavor =
         new java.awt.datatransfer.DataFlavor( edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyItem.class, "objectArrayPropertyItemFlavor" ); // e.toString()
 } catch(Exception e) {
   System.err.println("Error: ObjectArrayPropertyItemTransferable.java: "+str1); e.printStackTrace(); }
   }
 //LOB
   
 protected java.awt.datatransfer.DataFlavor[] flavors;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyItem objectArrayPropertyItem;

 public ObjectArrayPropertyItemTransferable (edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyItem objectArrayPropertyItem) {
  this.objectArrayPropertyItem = objectArrayPropertyItem;
  flavors = new java.awt.datatransfer.DataFlavor[2];
  flavors[0] = objectArrayPropertyItemFlavor;
  flavors[1] = java.awt.datatransfer.DataFlavor.stringFlavor;
  }

 public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors() {
  return flavors;
  }

 public boolean isDataFlavorSupported (java.awt.datatransfer.DataFlavor flavor) {
  //LOB for (DataFlavor flavor2 : flavors)
  int t_tam = flavors!=null ? flavors.length : 0;
  for (int i_i=0; i_i<t_tam; i_i++) {
   if (flavor.equals(flavors[i_i])) { //L  flavor2
    return true;
    }
   }
  return false;
  }

 public Object getTransferData (java.awt.datatransfer.DataFlavor flavor) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
  if (flavor.equals( objectArrayPropertyItemFlavor)) {
   return objectArrayPropertyItem;
  } else if (flavor.equals(java.awt.datatransfer.DataFlavor.stringFlavor)) {
   return objectArrayPropertyItem.getObjectArrayProperty() + "[" + objectArrayPropertyItem.getIndex() + "]";
  } else {
   System.err.println("Error: ObjectArrayPropertyItemTransferable.java: do not exists "+flavor);
   throw new java.awt.datatransfer.UnsupportedFlavorException( flavor );
   }
  }

 }
